﻿Option Explicit On
Option Strict On

Imports System
Imports System.ServiceModel

Namespace ACOM2000

    ''' <summary>
    ''' Implementation of the Callback contract for client side WCF callback handling
    ''' </summary>
    ''' <remarks></remarks>
    <CallbackBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple)> _
    Public Class ControllerCallbacks
        Implements IControllerCallbacks

#Region " Events "

        Public Event StateChanged As EventHandler
        Public Event ForwardPowerLedChanged As EventHandler(Of PowerLedChangedEventArgs)
        Public Event ReflectedPowerLedChanged As EventHandler(Of PowerLedChangedEventArgs)

#End Region

#Region " Callbacks "

        Public Sub ForwardPowerLedChangedCallback(e As PowerLedChangedEventArgs) Implements IControllerCallbacks.ForwardPowerLedChangedCallback
            RaiseEvent ForwardPowerLedChanged(Me, e)
        End Sub

        Public Sub ReflectedPowerLedChangedCallback(e As PowerLedChangedEventArgs) Implements IControllerCallbacks.ReflectedPowerLedChangedCallback
            RaiseEvent ReflectedPowerLedChanged(Me, e)
        End Sub

        Public Sub StateChangedCallback() Implements IControllerCallbacks.StateChangedCallback
            RaiseEvent StateChanged(Me, New EventArgs)
        End Sub

        Public Function BeginOnStateChanged(callback As System.AsyncCallback, asyncState As Object) As System.IAsyncResult Implements IControllerCallbacks.BeginOnStateChanged
            Dim EventAction As New Action(Sub() RaiseEvent StateChanged(Me, New EventArgs))
            Return EventAction.BeginInvoke(callback, asyncState)
        End Function

        Public Sub EndOnStateChanged(result As System.IAsyncResult) Implements IControllerCallbacks.EndOnStateChanged
            Dim EventAction As Action = DirectCast(DirectCast(result, System.Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, Action)
            EventAction.EndInvoke(result)
        End Sub

        Public Function BeginOnForwardPowerLedChanged(e As PowerLedChangedEventArgs, callback As System.AsyncCallback, asyncState As Object) As System.IAsyncResult Implements IControllerCallbacks.BeginOnForwardPowerLedChanged
            Dim EventAction As Action(Of PowerLedChangedEventArgs) = New Action(Of PowerLedChangedEventArgs)(Sub(args As PowerLedChangedEventArgs) RaiseEvent ForwardPowerLedChanged(Me, args))
            Return EventAction.BeginInvoke(e, callback, asyncState)
        End Function

        Public Function BeginOnReflectedPowerLedChanged(e As PowerLedChangedEventArgs, callback As System.AsyncCallback, asyncState As Object) As System.IAsyncResult Implements IControllerCallbacks.BeginOnReflectedPowerLedChanged
            Dim EventAction As Action(Of PowerLedChangedEventArgs) = New Action(Of PowerLedChangedEventArgs)(Sub(args As PowerLedChangedEventArgs) RaiseEvent ReflectedPowerLedChanged(Me, args))
            Return EventAction.BeginInvoke(e, callback, asyncState)
        End Function

        Public Sub EndOnForwardPowerLedChanged(result As System.IAsyncResult) Implements IControllerCallbacks.EndOnForwardPowerLedChanged
            Dim EventAction As Action(Of PowerLedChangedEventArgs) = DirectCast(DirectCast(result, System.Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, Action(Of PowerLedChangedEventArgs))
            EventAction.EndInvoke(result)
        End Sub

        Public Sub EndOnReflectedPowerLedChanged(result As System.IAsyncResult) Implements IControllerCallbacks.EndOnReflectedPowerLedChanged
            Dim EventAction As Action(Of PowerLedChangedEventArgs) = DirectCast(DirectCast(result, System.Runtime.Remoting.Messaging.AsyncResult).AsyncDelegate, Action(Of PowerLedChangedEventArgs))
            EventAction.EndInvoke(result)
        End Sub

#End Region

    End Class

End Namespace